module rbf_type
  integer, parameter :: i4b = selected_int_kind(9)
  integer, parameter :: i2b = selected_int_kind(4)
  integer, parameter :: i1b = selected_int_kind(2)
  integer, parameter :: dp  = kind(1.d00)
  integer, parameter :: dpc = kind( ( 1.d0, 1.d0 ) )
  integer, parameter :: LGT = kind(.true.)
 integer, parameter ::  NM = 5
  
!  real(dp), parameter :: SQRT2 = 1.41421356237309504880168872420969807856967
  real(dp), parameter :: EULER = 0.5772156649015328606065120900824024310422
!  real(dp), parameter :: pi    = 3.141592653589793238462643383279502884197
!  real(dp), parameter :: piO2  = 1.57079632679489661923132169163975144209858
!  real(dp), parameter :: TWOpi = 6.283185307179586476925286766559005768394
  
  real(dp), parameter :: Na       = 6.022141793d+23   ! mol^-1
  real(dp), parameter :: kb       = 1.380662000d-23   ! joules/kelvin
  real(dp), parameter :: kbT       = 4.11437276d-21   ! joules/kelvin
  real(dp), parameter :: epsi_vac = 8.854187817d-12   ! F/m permitivitty of free space (C^2/J/m)
  real(dp), parameter :: e_charge = 1.602176460d-19   ! electronic charge (C)

end module rbf_type

module precision
! Precision control

integer, parameter, public :: Single = kind(0.0) ! Single precision
integer, parameter, public :: Double = kind(0.0d0) ! Double precision

integer, parameter, public :: fp_kind = Double
!integer, parameter, public :: fp_kind = Single

end module precision


module variable
  use rbf_type
  use precision
  implicit none

  real(dp)    ,dimension(NM) :: DMC
  logical :: confine

  integer (i4b) :: nx,ny,nz,timesteps,typ_part

  namelist /input/ beta,ry,rz,nx,ny,nz, nematic_l, extrap_lw1, extrap_ls, ll1, lhat,q0,     &
       ULdG, surfactant, turns, width, Mw,Gw,Lw,Lr, coverage, random,  timesteps, copia, direction, & 
    extrap_lw2, pp_bulk, iseed,succm,dmc,confine,Nq0,npatch,psize,typ_part,frac_part
  
  namelist /addic/ nn, nodes, kk, mm, radius, Sbulk, LL, kks,  ALdG, Ws, Ww1, Ww2,          &
       gamma_s, gamma_w1, gamma_w2, molecule_area, area, molecules, vol_mol, c_max,xmax,ymax,zmax,    &
       step, archivo_cop, acepta, norm_aa, condition_aa, Uinitial, Sinitial,succm,dmc,ini_step
  
  !---- Input namelist ----
! Parameters
real(dp) :: pi

  integer(i4b) ni, nip, surfactant, direction, random, turns, copia, nband, mc_total,   &
       lband, clust_move,iseed,ini_step,npatch

  real(dp) beta, nematic_l, extrap_ls, extrap_lw1, ll1, pp_bulk,char_ener,psize,frac_part, invtemp , vi,ai ,           &
       ULdG, width, Lr, coverage, rmin, extrap_lw2, rband,succm,ry,rz,xmax,ymax,zmax,temp_ini,temp_fin,q0,dtime,Nq0,Mw,Gw,Lw
  real(dp), dimension(5) :: Lhat

  !---- Additional namelist ----
  integer(i4b) nn, nodes, mm, kk, step, archivo_cop, acepta

  real(dp) radius, ALdG, gamma_s, gamma_w1, Sbulk, Ws, Ww1,&
        molecule_area, area, molecules, vol_mol, c_max, Ww2,&
        gamma_w2, norm_aa, condition_aa, Uinitial, Sinitial

  real(dp), dimension(5) :: LL
  real(dp), dimension(4) ::kks 

  ! Other program variables
  real(dp), dimension(8) :: energy

  real(dp), dimension(:), allocatable :: xm, normal, chi,tangential,tangential_2,planar

  real(dp), dimension(:,:), allocatable :: q, a, da, ao_s,ao_w,da_ghost,da_local

!*******************************************************************
  integer(i4b),dimension(NM) :: mov_attempt,n_mov_accept

  logical , dimension (:,:,:) ,allocatable :: surface,inside
  integer(i4b) , dimension (:,:,:) ,allocatable ::  nee_cube
  logical , dimension (:) ,allocatable :: plan,wall
  logical , dimension (:) ,allocatable :: nn_surf
  real (dp) :: ddx,ddy,ddz,dddx,dddy,dddz,ddx2,ddy2,ddz2,iddx2,iddy2,iddz2
  real (dp) :: idxdy,idxdz,idydz
  integer (i4b),dimension(:,:) ,allocatable :: ix1_surf,ix2_surf
   integer (i4b),dimension(:,:) ,allocatable :: ix1,ix2,ix3,ix4,ix5

end module variable

module patch_module
  use rbf_type
  implicit none

  
   logical, dimension(:), allocatable :: inside_nano,surface_nano
   real(dp), dimension(:), allocatable :: pm
   integer , dimension(:), allocatable :: type_npatch
  


end module patch_module
module ptrajectory
  use rbf_type
  implicit none
  namelist /input2/ cmx_part,cmy_part,cmz_part,theta,phi
  real(dp) x1, y1, z1
  real(dp) ,dimension(3):: theta,phi,rr
  real(dp) ,dimension(3):: cmx_part,cmy_part,cmz_part
end module ptrajectory
